<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
  <div region="center" style="padding:0px;border:0px">
  	<div class="searchPanel">
   		<input placeholder="输入学号或用户名查询申请" id='searchInput' maxlength="15"> <button class="searchBtn"  onclick="search()">查询</button>
   	</div>
  </div>
</div>

<style>
	.searchPanel{
		margin: auto;
	    margin-top: 20%;
	    width: 350px;
	}
	
	#searchInput {
		border:1px solid #ddd !important;
		color:black;
		font-size:20px;
		padding: 10px;
		width:260px;
	}
	
	.searchBtn{
		font-size:18px;
		padding-top: 12px;
   		padding-bottom: 10px;
   		padding-left:20px;
   		padding-right:20px;
	}
	
</style>
 
<script type="text/javascript">
	 $(document).ready(function(){
	 	$('#searchInput').focus();
	 	
	 	$('#searchInput').keypress(function(e){
	 		 if(e.which == 13) {  
	 			search();
	 		 }
	 	});
	 }); 
	 
	 function search(){
		 var no = $('#searchInput').val();
		 $.ajax({
			 url:"deviceOutStockController.do?searchApply&studentNo="+no,
			 success:function(d){
				d = $.parseJSON(d);
				if(d.length > 1){ //选择要出库的申请
					showSelectApplyWindow(no);
					
				}else if(d.length == 1){ 
					showOutStockWindow(d);
				}
				else{ //显示出库操作的对话框
					tip("未查询到设备预约或使用申请!");
				}
			 }
		 })
	 }
	 
	 function showSelectApplyWindow(no){
		 var addurl = 'deviceOutStockController.do?showSelectApply&no='+no;
		  $.dialog({
			  	id:'charge',
				content: 'url:'+addurl,
				lock : true,
				zIndex: 50, 
				width:600,
				height:450,
				title:'选择申请', 
				opacity : 0.3,
				cache:false, 
				ok: function(){
				    	iframe = this.iframe.contentWindow;
				    	var data = iframe.getSelect();
				    	if (!data || data.length==0) {
							tip('请选择申请项目');
							return false;
						}else{
							this.close();
							showOutStockWindow(data);
							return false;
						} 
				  },
			    cancelVal: '关闭',
			    cancel: true /*为true等价于function(){}*/
		});
	 }
	 
	 function successSelectApply(data){
		 alert(data);
	 }
	 
	 var optSuccess = false;
	 function showOutStockWindow(data){
		var data = data[0];
		
		if("APPOINT" == data.type){
			h = 250;
		}else{
			h = 400;
		}
 		 
		 var addurl = 'deviceOutStockController.do?showOutStockWin&id='+data.id+"&type="+data.type;
		  $.dialog({
			  	id:'deviceOutStock',
				content: 'url:'+addurl,
				lock : true,
				zIndex: 60, 
				width:500,
				height:h,
				title:'设备出库', 
				opacity : 0.3,
				cache:false, 
			    cancelVal: '关闭',
			    cancel: true /*为true等价于function(){}*/,
			    close:function(){
			    	if(window.top.optSuccess)tip('设备出库成功！');
			    }
			});
	 }
</script>